<template>
  <div class="articleList">
    <list-item :articleList="articleList" :articleTotal="articleTotal" :pageindex="pageindex"></list-item>
    <div class="loadMoreArticleBtn" @click="loadMoreArticleBtnClick" v-if="articleList.length!==0">
      {{loadMore}}
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import ResizeMixin from 'common/mixin/ResizeHandler'
// import Carrousel from 'base/archive/carrousel'
import listItem from 'base/articleList/list.vue'
export default {
  name: 'articleList',
  data() {
    return {}
  },
  mixins: [ResizeMixin],
  computed: {
    loadMore() {
      return this.articleTotal > this.articleList.length ? '加载更多文章' : '没有更多文章了'
    },
    ...mapGetters([
      'articleList',
      'articleTotal',
      'pageindex',
      'pagesize'
    ])
  },
  created() {
    if (this.articleList.length === 0) {
      this.getArticleList()
    }
  },
  mounted() {},
  methods: {
    getArticleList() {
      if (this.articleList.length === 0) {
        this.query = {
          pageindex: this.pageindex,
          pagesize: this.pagesize
        }
      } else {
        this.query = {
          pageindex: Math.floor(this.articleList.length / 10 + 1)
        }
      }
      this.$store.dispatch('GetArticleList', this.query)
    },
    loadMoreArticleBtnClick() {
      if (this.articleTotal > this.articleList.length) {
        this.getArticleList()
      }
    }
  },
  components: {
    listItem
  }
}
</script>
<style lang="scss" scoped>
.loadMoreArticleBtn {
  margin: 10px 1px;
  text-align: center;
  height: 36px;
  line-height: 36px;
  border-radius: 3px;
  user-select: none;
  background-color: rgba(250,250,250,0.5);
  cursor: pointer;
  &:hover {
    background-color: rgba(250,230,250,0.8);
    box-shadow: rgba(0, 0, 0, 0.3) 0px 1px 6px;
  }
}
</style>
